package com.smedi.ismedi.inmail.core.application.query.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smedi.ismedi.authority.starter.util.VerifyHelper;
import com.smedi.ismedi.inmail.core.application.command.LoginLogOrgStaticsListCommand;
import com.smedi.ismedi.inmail.core.application.command.LoginLogOrgStaticsPageCommand;
import com.smedi.ismedi.inmail.core.application.convert.AppConverter;
import com.smedi.ismedi.inmail.core.application.query.LoginLogOrgStaticsQueryService;
import com.smedi.ismedi.inmail.core.domain.aggregatemodel.LoginLogOrgStatics;
import com.smedi.ismedi.inmail.core.port.adapter.persistence.model.LoginLogOrgStaticsEntity;
import com.smedi.ismedi.inmail.core.port.adapter.persistence.mybatis.mapper.LoginLogOrgStaticsMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 查询服务实现类
 *
 * @author jiangqinxuan
 * @date 2021/07/30
 */
@Service
@AllArgsConstructor
@Slf4j
@SuppressWarnings("all")
public class LoginLogOrgStaticsQueryServiceImpl implements LoginLogOrgStaticsQueryService {
    private final LoginLogOrgStaticsMapper loginLogOrgStaticsMapper;
    private final AppConverter appConverter;

    @Override
    public Page<LoginLogOrgStatics> page(LoginLogOrgStaticsPageCommand loginLogOrgStaticsPageCommand) {
        Page<LoginLogOrgStaticsEntity> loginLogOrgStaticsEntityPage = loginLogOrgStaticsMapper.selectPage(new Page<>(loginLogOrgStaticsPageCommand.getCurrent(), loginLogOrgStaticsPageCommand.getSize()),
                new LambdaQueryWrapper<LoginLogOrgStaticsEntity>()
                        .eq(VerifyHelper.isAvailable(loginLogOrgStaticsPageCommand.getOrganizationId()), LoginLogOrgStaticsEntity::getOrganizationId, loginLogOrgStaticsPageCommand.getOrganizationId())
                        .orderBy(true, true, LoginLogOrgStaticsEntity::getDisplayOrder));
        return appConverter.loginLogOrgStaticsEntityToLoginLogOrgStatics(loginLogOrgStaticsEntityPage);
    }

    @Override
    public List<LoginLogOrgStatics> list(LoginLogOrgStaticsListCommand loginLogOrgStaticsListCommand) {
        List<LoginLogOrgStaticsEntity> loginLogOrgStaticsEntities = loginLogOrgStaticsMapper.selectList(
                new LambdaQueryWrapper<LoginLogOrgStaticsEntity>()
                        .eq(VerifyHelper.isAvailable(loginLogOrgStaticsListCommand.getOrganizationId()), LoginLogOrgStaticsEntity::getOrganizationId, loginLogOrgStaticsListCommand.getOrganizationId())
                        .orderBy(true, true, LoginLogOrgStaticsEntity::getDisplayOrder));
        return appConverter.loginLogOrgStaticsEntityToLoginLogOrgStatics(loginLogOrgStaticsEntities);
    }
}
